home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / Serial Toolkit / Source Code / configureSPort.p < prev    next >
Text File  |  1988-11-18  |  7KB  |  181 lines

  1. (*
  2.     configureSPort keyword,keyword, ... — Set the configuration of the port, as specified by a
  3.         keyword list. The following keywords are allowed:
  4.  
  5.                 modemPort/port1 - Use the modem port.
  6.                 printerPort/port2 - Use the printer port.
  7.                 baud300/baud600/baud1200/baud1800/baud2400/baud3600/
  8.                 baud4800/baud7200/baud9600/baud19200/baud57600 - Set the baud rate.
  9.                 stop10/stop15/stop20 - Set the number of stop bits to 1.0, 1.5, or 2.0.
  10.                 parityOff/parityOdd/parityEven - Set the parity.
  11.                 data5/data6/data7/data8 - Set the number of data bits.
  12.                 XOnOutOn/XOnOutOff - Enable or disable character flow control out outgoing data.
  13.                 CTSOutOn/CTSOutOff - Enable or disable signal flow control on outgoing data.
  14.                 linefeedOn/linefeedOff - Enable or disable sending of linefeeds after each carriage return.
  15.                 echoOn/echoOff - Enable or disable echoing of the input back to the output.
  16.                 editOn/editOff - Enable or disable editing of the input from the input (i.e., backspaces).
  17.                 stripOn/stripOff - Enable or disable striping of the top bit of the input.
  18.                 stripControlsOn/stripControlsOff - Enable or disable striping of control characters (except return and tab).
  19.                 autoWrapOn/autoWrapOff - Enable or disable automatic wrapping of input and output.
  20.  
  21.     To compile and link this file using Macintosh Programmer's Workshop,
  22.  
  23.         pascal -w configureSPort.p
  24.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=7035 -sn Main=configureSPort ∂
  25.             configureSPort.p.o "{MPW}"Libraries:interface.o
  26.  
  27.     © Copyright 1987,88 by Apple Computer, Inc.
  28.  
  29.     Initial coding 9/87 by Harry R. Chesley.
  30. *)
  31.  
  32. {$R-}
  33.  
  34. {$S configureSPort }     { Segment name must be the same as the command name. }
  35.  
  36. unit DummyUnit;
  37.  
  38. interface
  39.  
  40. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  41.  
  42. procedure EntryPoint(paramPtr: XCmdPtr);
  43.     
  44. implementation
  45.  
  46. type
  47.  
  48. Str31 = String[31];
  49.  
  50. procedure configureSPort(paramPtr: XCmdPtr); forward;
  51.  
  52. procedure EntryPoint(paramPtr: XCmdPtr);
  53.  
  54.     begin
  55.         configureSPort(paramPtr);
  56.     end;
  57.  
  58. procedure configureSPort(paramPtr: XCmdPtr);
  59.  
  60.     var i: integer;
  61.         parmStr: str255;
  62.         hasChanged: boolean;
  63.  
  64.     {$I XCmdGlue.inc}
  65.  
  66.     procedure Fail(errMsg: Str255); { set theResult and quit }
  67.         begin
  68.             paramPtr^.returnValue := PasToZero(errMsg);
  69.             exit(configureSPort);
  70.         end;
  71.  
  72.     {$I SPortUtil.inc}
  73.  
  74.     procedure changeByte(mask, value: longInt);
  75.  
  76.         begin
  77.             ThisSPort.byteConfig := BitOr(BitAnd(BitNot(mask),ThisSPort.byteConfig),value);
  78.         end;
  79.  
  80.     procedure updateIfChanged;
  81.         { If there have been any changes in the configuration, set the port. }
  82.  
  83.         begin
  84.             if hasChanged then
  85.                 begin
  86.                     { Save the settings. }
  87.                     Globals^^.ports[Globals^^.selectedPort] := ThisSPort;
  88.             
  89.                     { Open it if it hasn't already been opened. }
  90.                     EnsureOpenPort;
  91.                     { Set the port. }
  92.                     with ThisSPort do
  93.                         begin
  94.                             if SerHShake(portInDev,shakes) <> noErr then Fail('SerHShake failed');
  95.                             if SerHShake(portOutDev,shakes) <> noErr then Fail('SerHShake failed');
  96.                             if (SerReset(portInDev,byteConfig) <> noErr) or
  97.                                     (SerReset(portOutDev,byteConfig) <> noErr) then
  98.                                 Fail('SerReset failed');
  99.                         end;
  100.                     hasChanged := false;
  101.                 end;
  102.         end;
  103.  
  104.     procedure selectPort(whichPort: SPortSel);
  105.         { Switch to a new port. }
  106.  
  107.         begin
  108.             updateIfChanged;
  109.             Globals^^.selectedPort := whichPort;
  110.             ThisSPort := Globals^^.ports[whichPort];
  111.         end;
  112.  
  113.     begin
  114.         if paramPtr^.paramCount = 0 then Fail('no parameters');
  115.  
  116.         SetUpSPortGlobals;
  117.  
  118.         { Go through the configuration parameters, one by one...}
  119.         hasChanged := false;
  120.         with ThisSPort do
  121.             for i := 1 to paramPtr^.paramCount do
  122.                 begin
  123.                     GetStrParm(i,parmStr);
  124.                     if StringEqual(parmStr,'modemPort') or StringEqual(parmStr,'port1') then
  125.                         begin
  126.                             selectPort(sPortA);
  127.                             cycle;
  128.                         end
  129.                     else if StringEqual(parmStr,'printerPort') or StringEqual(parmStr,'port2') then
  130.                         begin
  131.                             selectPort(sPortB);
  132.                             cycle;
  133.                         end
  134.                     else if StringEqual(parmStr,'baud300') then changeByte($003FF,baud300)
  135.                     else if StringEqual(parmStr,'baud600') then changeByte($003FF,baud600)
  136.                     else if StringEqual(parmStr,'baud1200') then changeByte($003FF,baud1200)
  137.                     else if StringEqual(parmStr,'baud1800') then changeByte($003FF,baud1800)
  138.                     else if StringEqual(parmStr,'baud2400') then changeByte($003FF,baud2400)
  139.                     else if StringEqual(parmStr,'baud3600') then changeByte($003FF,baud3600)
  140.                     else if StringEqual(parmStr,'baud4800') then changeByte($003FF,baud4800)
  141.                     else if StringEqual(parmStr,'baud7200') then changeByte($003FF,baud7200)
  142.                     else if StringEqual(parmStr,'baud9600') then changeByte($003FF,baud9600)
  143.                     else if StringEqual(parmStr,'baud19200') then changeByte($003FF,baud19200)
  144.                     else if StringEqual(parmStr,'baud57600') then changeByte($003FF,baud57600)
  145.                     else if StringEqual(parmStr,'stop10') then changeByte($0C000,stop10)
  146.                     else if StringEqual(parmStr,'stop15') then changeByte($0C000,stop15)
  147.                     else if StringEqual(parmStr,'stop20') then changeByte($0C000,stop20)
  148.                     else if StringEqual(parmStr,'parityOff') then changeByte($03000,noParity)
  149.                     else if StringEqual(parmStr,'parityOdd') then changeByte($03000,oddParity)
  150.                     else if StringEqual(parmStr,'parityEven') then changeByte($03000,evenParity)
  151.                     else if StringEqual(parmStr,'data5') then changeByte($00C00,data5)
  152.                     else if StringEqual(parmStr,'data6') then changeByte($00C00,data6)
  153.                     else if StringEqual(parmStr,'data7') then changeByte($00C00,data7)
  154.                     else if StringEqual(parmStr,'data8') then changeByte($00C00,data8)
  155.                     else if StringEqual(parmStr,'XOnOutOn') then shakes.fXOn := 1
  156.                     else if StringEqual(parmStr,'XOnOutOff') then shakes.fXOn := 0
  157.                     else if StringEqual(parmStr,'CTSOutOn') then shakes.fCTS := 1
  158.                     else if StringEqual(parmStr,'CTSOutOff') then shakes.fCTS := 0
  159.                     else if StringEqual(parmStr,'linefeedOn') then sendLFs := true
  160.                     else if StringEqual(parmStr,'linefeedOff') then sendLFs := false
  161.                     else if StringEqual(parmStr,'echoOn') then doEcho := true
  162.                     else if StringEqual(parmStr,'echoOff') then doEcho := false
  163.                     else if StringEqual(parmStr,'editOn') then doEdit := true
  164.                     else if StringEqual(parmStr,'editOff') then doEdit := false
  165.                     else if StringEqual(parmStr,'stripOn') then stripIncoming := true
  166.                     else if StringEqual(parmStr,'stripOff') then stripIncoming := false
  167.                     else if StringEqual(parmStr,'stripControlsOn') then stripControls := true
  168.                     else if StringEqual(parmStr,'stripControlsOff') then stripControls := false
  169.                     else if StringEqual(parmStr,'autoWrapOn') then autoWrap := true
  170.                     else if StringEqual(parmStr,'autoWrapOff') then autoWrap := false;
  171.                     hasChanged := true;
  172.                 end;
  173.  
  174.         { Set it if it's been changed. }
  175.         updateIfChanged;
  176.         { And make sure the current port is open, even if we didn't change anything. }
  177.         EnsureOpenPort;
  178.     end;
  179.  
  180. end.
  181.